@extends('layouts.master')
@push('stylesheets')
    <link href="{{ URL::asset('/static/web/css/plugins/sweetalert/sweetalert.css')}}?v=33" rel="stylesheet">
@endpush
@section('content')
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox">
                <div class="ibox-content">
                    <form class="layui-form" action="">
                        <div class="layui-inline">
                            <div class="layui-inline">
                                <label class="layui-form-label">提现状态:</label>
                                <div class="layui-input-inline">
                                    <select name="query[type]" lay-verify="">
                                        <option value="">全部</option>
                                        @foreach($queryData['status'] as $index=>$item)
                                            <option value="{{$index}}" {{ ($query['status']) && $query['status']==$index ? 'selected': ''}}>{{$item}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-inline">
                                <label class="layui-form-label">提现方式:</label>
                                <div class="layui-input-inline">
                                    <select name="query[type]" lay-verify="">
                                        <option value="">全部</option>
                                        @foreach($queryData['type'] as $index=>$item)
                                            <option value="{{$index}}" {{ ($query['type']) && $query['type']==$index ? 'selected': ''}}>{{$item}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-inline">
                                <label class="layui-form-label">打款方式:</label>
                                <div class="layui-input-inline">
                                    <select name="query[type]" lay-verify="">
                                        <option value="">全部</option>
                                        @foreach($queryData['pay_type'] as $index=>$item)
                                            <option value="{{$index}}" {{ ($query['pay_type']) && $query['pay_type']==$index ? 'selected': ''}}>{{$item}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-inline">
                                <label class="layui-form-label">关键字:</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="query[keywords]" lay-verify="" placeholder="昵称/真实姓名/手机号"
                                           style="width: 200px;" value="{{$query['keywords']}}" autocomplete="off"
                                           class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">申请时间:</label>
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" class="layui-input  start_time" value="{{$query['start_time']}}"
                                       name="query[start_time]"
                                       readonly>
                            </div>
                            -
                            <div class="layui-input-inline" style="width: 150px;">
                                <input type="text" class="layui-input end_time" value="{{$query['end_time']}}"
                                       name="query[end_time]"
                                       readonly>
                            </div>
                        </div>
                        <div class="layui-inline" style="padding-bottom: 5px">
                            <div class="layui-input-inline">
                                <input type="hidden" name="page_num" value="{{$currentPageNum}}">
                                <button name="submit" class="btn btn-success" type="submit">搜索</button>
                            </div>
                        </div>
                    </form>

                    @include('common.toolbar', ['pager' => $pager])

                    <form class="layui-form form-horizontal" id="ajaxform">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>会员</th>
                                <th>提现金额</th>
                                <th>提现方式</th>
                                <th>打款方式</th>
                                <th>申请时间</th>
                                <th>备注</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($pager as $item)
                                <tr>
                                    <td>{{$item->id}}</td>
                                    <td>
                                        <img src="{{$item->user->avatar}}"
                                             class="rounded-circle img-sm img_pop_show"/><br/>
                                        {{$item->user->nickname}}<br>
                                        {{$item->user->mobile}}
                                    </td>
                                    <td>
                                        ￥{{$item->balance}}
                                        @if($item->commission>0)
                                            <br/>
                                            <span class="text-danger">手续费{{$item->commission}}</span>
                                        @endif
<br />
                                    </td>
                                    <td>
                                        @if($item->type=='bank')
                                            线下银行卡打款<br/>
                                            姓名:{{$item->name}}<br>
                                            银行卡号:{{$item->cardnum}}<br>
                                            所属银行:{{$item->bankname}}<br>
                                            银行开户地址:{{$item->bank_address}}<br>
                                        @elseif($item->type=='alipay')
                                            线下支付宝打款<br/>
                                            支付宝:{{$item->alipay_code}}<br>
                                        @elseif($item->type=='weixin')
                                            线下微信打款<br/>
                                            昵称:{{$item->user->nickname}}<br>
                                            微信号:{{$item->weixin}}<br>
                                        @endif
                                    </td>
                                    <td>{{$item->payTypeText}}</td>
                                    <td>{{$item->created_at}}</td>
                                    <td>{{$item->remark}}</td>
                                    <td>
                                        @if($item->status==0)
                                            <span class="label label-info">待打款</span>
                                        @elseif($item->status==1)
                                            <span class="label label-success">打款成功</span>
                                        @elseif($item->status==-2)
                                            <span class="label label-danger">打款失败</span><br/>
                                            失败原因: {{$item->fail_msg}}<br/>
                                            失败时间: @php echo date('Y-m-d H:i:s',$item->fail_time); @endphp
                                        @elseif($item->status==-1)
                                            <span class="label label-warning">驳回申请</span>
                                        @endif
                                    </td>
                                    <td data-id="{{$item->id}}">
                                        @if($item->status==0 || $item->status==-2)
                                            <a data-url="{{route('balance.withdraw_apply.check',['id'=>$item->id,'pay_type'=>1,'status'=>1])}}" data-title="确定线下手动打款？" href="javascript:;" data-method="post" class="btn btn-success ajax-confirm" type="button"><i class="fa fa-check"></i> 线下打款</a>
                                            <a data-url="{{route('balance.withdraw_apply.check',['id'=>$item->id,'pay_type'=>2,'status'=>1])}}" data-title="确定线上打款？" href="javascript:;" data-method="post" class="btn btn-success ajax-confirm" type="button"><i class="fa fa-check"></i> 线上打款</a>
                                            <a href="javascript:;"
                                               class="btn btn-danger checkFail" type="button"><i class="fa fa-power-off"></i> 驳回</a>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                    @include('common.pagination', ['pager' => $pager])
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script>
        layui.use(['laydate', 'element', 'form'], function () {
            var laydate = layui.laydate, element = layui.element;
            var form = layui.form;
            var layer = layui.layer;

            //日期时间选择器
            laydate.render({
                elem: '.start_time'
                , type: 'datetime'
            });
            laydate.render({
                elem: '.end_time'
                , type: 'datetime'
            });
        });


        require(["{{ URL::asset('/static/web/js/plugins/sweetalert/sweetalert.min.js')}}"], function (swal) {
            layui.use(['laydate', 'element'], function () {
                $(".checkFail").click(function () {
                    //批量操作
                    // if ($(this).data("batch")) {
                    //     var batch = $(this).data("batch");
                    //     var id = [];
                    //     $(".check_item:checked").each(function () {
                    //         var value = $(this).data(batch);
                    //         id.push(value);
                    //     });
                    //     if (id.length <= 0) {
                    //         layer.msg('请选择要操作的数据', {time: 2000, icon: 5});
                    //         return;
                    //     }
                    // } else {
                        var id = $(this).parent().data('id');
                    // }
                    swal({
                        title: '驳回原因',
                        input: 'textarea',
                        confirmButtonText: "提交",
                        cancelButtonText: "取消",
                        showCancelButton: true
                    }).then(function(result) {
                        var remark = result.value;
                        if(remark && result.dismiss!='cancel'){
                            var index = layer.load(0);
                            $.ajax({
                                url: '{{route("balance.withdraw_apply.check")}}',
                                type: 'POST',
                                data: {id:id,fail_msg:remark,status:-1},
                                dataType: "json",
                                success: function (result) {
                                    layer.close(index);
                                    if (result.errno == 0) {
                                        layer.msg(result.message, {time: 2000, icon: 6});
                                        location.reload();
                                    } else {
                                        layer.msg(result.message, {time: 2000, icon: 5});
                                    }
                                }
                            });
                        }

                    })
                })
            });
        })
    </script>
@endsection